package cn.school.mybatis.service;

import cn.school.mybatis.dao.AdminDao;
import cn.school.mybatis.pojo.Admin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

//业务逻辑bean
//服务层,调用dao方法
@Service
@Transactional
public class AdminService {
    @Autowired
    private AdminDao adminDao;

    //增加
    public int add(Admin admin) {
        return adminDao.add(admin);
    }

    //删除
    public int del(int id) {
        return adminDao.del(id);
    }

    //修改
    public int update(Admin admin) {
        return adminDao.update(admin);
    }

    //id查单个
    public Admin get(int id) {
        return adminDao.get(id);
    }

    //查询总数
    public int get() {
        return adminDao.searchCount();
    }

    //查找
    public List<Admin> search(Map map) {
        return adminDao.search(map);
    }

    //查全部
    public List<Admin> searchAll() {
        Map map = new HashMap();
        map.put("orderBy","id asc");
        map.put("pageNo",1);
        map.put("pageSize",5);
//        map.put("username",username);
//        map.put("password",password);
        return this.search(map);
    }

    //账号密码查单个
    public List<Admin> searchAdmin(String username,String password) {
        Map map = new HashMap();
        map.put("orderBy","id asc");
        map.put("username",username);
        map.put("password",password);
        return this.search(map);
    }
    //账号密码查单个
    public boolean checkAdmin(Admin admin) {
        Map map = new HashMap();
        map.put("username",admin.getUsername());
        map.put("password",admin.getPassword());
        return this.search(map).size()>0;
    }

}
